/*! \file OrbitEvent.inl
 *	\brief 
 *
 *	created:	2010/09/08
 *	created:	8:9:2010   12:42
 *	filename: 	s:\DNG-Code\Kiev\Modules\Orbit\Protection\Include\OrbitEvent.inl
 *	file path:	s:\DNG-Code\Kiev\Modules\Orbit\Protection\Include
 *	file base:	OrbitEvent
 *	file ext:	inl
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
namespace tt{
namespace core{

template<typename Handler>
EventBase<Handler>::EventBase()
: m_handlers()
{

}

template<typename Handler>
EventBase<Handler>::~EventBase()
{

}

template<typename Handler>
EventBase<Handler>& EventBase<Handler>::operator += ( const Handler& handler )
{
	Handlers::iterator it = std::find( m_handlers.begin(), m_handlers.end(), handler );
	if( it == m_handlers.end() )
	{
		m_handlers.push_back( handler );
	}
	return *this;
}

//////////////////////////////////////////////////////////////////////////
inline
void Event<Functor0>::operator()()
{
	Handlers::iterator last_handler = m_handlers.end();
	for( Handlers::iterator it = m_handlers.begin(); it != last_handler; ++it )
	{
		Handler& event = *it;
		event();
	}
}

//////////////////////////////////////////////////////////////////////////
template<typename Arg1>
void Event< Functor1<Arg1> >::operator()( Arg1 arg1 )
{
	Handlers::iterator last_handler = m_handlers.end();
	for( Handlers::iterator it = m_handlers.begin(); it != last_handler; ++it )
	{
		Handler& event = *it;
		event(arg1);
	}
}

//////////////////////////////////////////////////////////////////////////
template<typename Arg1, typename Arg2>
void Event< Functor2<Arg1, Arg2> >::operator()( Arg1 arg1, Arg2 arg2 )
{
	Handlers::iterator last_handler = m_handlers.end();
	for( Handlers::iterator it = m_handlers.begin(); it != last_handler; ++it )
	{
		Handler& event = *it;
		event(arg1, arg2);
	}
}

} //namespace core
} //namespace tt
